package com.jishuo.nontax.web.bill;

import com.jishuo.base.annotation.UserAuthority;
import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.GridResult;
import com.jishuo.base.bean.Pagination;
import com.jishuo.base.bean.vo.UserVO;
import com.jishuo.base.config.AppConfig;
import com.jishuo.base.service.UserService;
import com.jishuo.nontax.bean.vo.StudentVO;
import com.jishuo.nontax.bfc.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 学生缴款查询
 */
@Slf4j
@Controller
@RequestMapping(value = "/bill/student", name = "学生缴费")
@UserAuthority(menu={"bill/student","sys/basedata/basedata"})
public class StudentController {

    @Resource
    private StudentService studentService;
    @Resource
    private UserService userService;
    private String prefix = "bill/";

    @RequestMapping(value = {"student"}, name = "学生首页")
    public String index() {
        return prefix + "student";
    }

    @ResponseBody
    @RequestMapping(value = "listStudent", name = "学生缴费列表")
    public GridResult<StudentVO> listStudent(StudentVO studentVO, Pagination pagination) {
        return new GridResult<>(studentService.listStudent(studentVO, pagination));
    }

    @ResponseBody
    @RequestMapping(value = "sendStudent", name = "发送学校缴费信息")
    public BaseResult sendStudent(@RequestParam String billids, String usercode, String userpwd, HttpSession session) {
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return studentService.sendStudent(billids);
    }

    @ResponseBody
    @RequestMapping(value = "cleanStudent",name = "冲销学校缴费信息")
    public  BaseResult  cleanStudent(@RequestParam String billids, String usercode, String userpwd, HttpSession session){
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return  studentService.cleanStudent(billids, usercode);
    }

    @ResponseBody
    @RequestMapping(value = "studentExport", name = "学校缴费导出")
    public void studentExport(long bankid, String paybankdt, HttpServletResponse response) {
        studentService.studentExport(bankid, paybankdt, response);
    }
}
